package main

import (
	"dev"
	"fmt"
)

func main() {

	//面向对象编程方式
	conn := &dev.Mysql{"127.0.0.1", 3306, "root", "root", "go"}
	conn.Connect()
	sql := &dev.Sql{"select * from User"}
	sql.Curd()

	//接口
	var doing dev.Do
	bird := new(dev.Bird)
	doing = bird
	ifly := doing.Fly()
	irun := doing.Run()
	fmt.Println(ifly)
	fmt.Println(irun)
	doing.Test()

	//切片的使用
	slice := make([]int, 3)
	slice[0] = 0
	slice[1] = 1
	slice[2] = 2
	slice = append(slice, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
	fmt.Printf("%v\n", len(slice))
	fmt.Printf("%v\n", cap(slice))

	aa := []int{1, 1, 1}
	aa = append(aa, 1, 2, 3, 7)
	fmt.Printf("%v\n", len(aa))
	fmt.Printf("%v\n", cap(aa))

	//函数使用
	sum1 := 10;
	//传引用
	dev.Sum(&sum1)
	fmt.Println(sum1)
	sum2 := 10
	//传值
	dev.SumA(sum2)
	fmt.Println(sum2)

	//回调函数
	dev.Jisuan(5, 10, func(a, b int) int {
		sum := a + b
		fmt.Println(sum)
		return sum
	})

	//空接口和类型断言
	var bb interface{}
	bb = 5

	switch bb.(type) {
	case int:
		fmt.Println("this is a int")
	case float32:
		fmt.Println("this is a float32")
	case float64:
		fmt.Println("this is a float64")
	}
}
